<?php

use Symfony\Component\HttpKernel\Controller\ControllerReference;
echo $view['actions']->render(new ControllerReference('FiestissimaCRM:Index:header'));

?>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h2 class="page-header">Productos
                <div class="pull-right">
                    <button id="btnAgregarTipo" class="btn btn-info btn-xs" type="button" data-toggle="modal" data-target="#modalAgregarTipo">
                        <i class="fa fa-edit fa-fw"></i> Agregar Tipo
                    </button>
                </div>
                </h2>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="fa fa-shopping-cart fa-fw"></i> <?php echo $type; ?>
                        <div class="pull-right">
                            <button id="btnAgregarMarca" class="btn btn-info btn-xs" type="button" data-toggle="modal" data-target="#modalAgregarMarca">
                                <i class="fa fa-edit fa-fw"></i> Agregar Marca
                            </button>
                        </div>
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="table-responsive" id="divTableClientesEmpresa">
                                    <?php
                                    if(count($productos)>0)
                                    {
                                        ?>
                                        <table class="table table-hover table-striped" id="tableClientesEmpresa">
                                            <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>Nombre</th>
                                                <th>Marca</th>
                                                <th>Stock</th>
                                                <th>Alerta de Stock</th>
                                                <th>&nbsp;</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php
                                            foreach($productos as $p)
                                            {
                                                if($p->getPrStock() > $p->getPrStockAlerta())
                                                {
                                                    echo "<tr class='success'>";
                                                }elseif($p->getPrStock() == $p->getPrStockAlerta()){
                                                    echo "<tr class='warning'>";
                                                }else{
                                                    echo "<tr class='danger'>";
                                                }

                                                echo "
                                                            <td id=\"prId\">".$p->getPrId()."</td>
                                                            <td>".$p->getPrNombre()."</td>
                                                            <td>".$p->getBrand()."</td>
                                                            <td id=\"prStock".$p->getPrId()."\">".$p->getPrStock()."</td>
                                                            <td id=\"prStockAlerta".$p->getPrId()."\">".$p->getPrStockAlerta()."</td>
                                                            <td>
                                                                <button type=\"button\" class=\"btnStock btn btn-primary btn-sm\" data-toggle=\"modal\" data-target=\"#stockProductoModal\">
                                                                <i class=\"fa fa-edit fa-fw\"></i> Actualizar Stock
                                                                </button>
                                                            </td>
                                                            <td>
                                                                <button type=\"button\" class=\"btnVerPrecios btn btn-primary btn-sm\" data-toggle=\"modal\" data-target=\"#verPreciosModal\">
                                                                <i class=\"fa fa-edit fa-fw\"></i> Ver precios
                                                                </button>
                                                            </td>
                                                        </tr>
                                                    ";
                                            }
                                            ?>
                                            </tbody>
                                        </table>
                                    <?php
                                    }else {
                                        echo "No hay productos del tipo {$type}.";
                                    }
                                    ?>
                                </div>
                                <!-- /.table-responsive -->
                            </div>
                            <!-- /.col-lg-4 (nested) -->
                        </div>
                        <!-- /.row -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
    <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->

    <!--  MODAL ACTUALIZAR STOCK-->
    <div class="modal fade" id="stockProductoModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content panel-info">
                <div class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="modalStockTitle">Stock del producto</h4>
                </div>
                <div class="modal-body">
                    <h4 class="modal-title"><i class="fa fa-circle-o-notch fa-spin"></i></h4>
                    <form id="formStockProducto">
                        <input type="hidden" value="" class="form-control" id="pr_id" name="pr_id">
                        <div class="form-group row">
                            <div class="col-sm-4">
                                <label for="prodStock" class="control-label">Stock</label>
                                <div>
                                    <input type="text" class="form-control" id="prodStock" name="prodStock">
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <label for="prodStockAlerta" class="control-label">Stock Alerta</label>
                                <div>
                                    <input type="text" class="form-control" id="prodStockAlerta" name="prodStockAlerta">
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <label for="btnGuardarStock" class="control-label">&nbsp;</label>
                                <div>
                                    <button class="btn btn-primary" type="button" id="btnGuardarStock">Guardar Stock</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!--  /MODAL ACTUALIZAR STOCK-->

    <!--  MODAL AGREGAR PRECIOS  -->
    <div class="modal fade" id="verPreciosModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content panel-info">
                <div class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="modalPreciosTitle">Precios</h4>
                </div>
                <div class="modal-body">
                    <h4 class="modal-title">Actualizar precio</h4>
                    <form id="formNuevoPrecio">
                        <input type="hidden" value="" class="form-control" id="pr_id" name="pr_id">
                    <div class="form-group row">
                        <div class="col-sm-3">
                            <label for="precioValor" class="control-label">Valor</label>
                            <div class="input-group">
                                <div class="input-group-addon">$</div>
                                <input type="text" class="form-control" id="precioValor" name="precioValor">
                            </div>
                        </div>
                        <div class="col-sm-3" id="fechaPicker">
                            <label for="inputInstancia" class="control-label">Desde</label>
                            <div class="input-group date">
                                <input type='text' class="form-control" id="fechaDesde" name="fechaDesde"/>
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                        <div class="col-sm-3" id="fechaPicker">
                            <label for="inputInstancia" class="control-label">Hasta</label>
                            <div class="input-group date">
                                <input type='text' class="form-control" id="fechaHasta" name="fechaHasta"/>
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <label for="inputInstancia" class="control-label">&nbsp;</label>
                            <div>
                                <button class="btn btn-primary" type="button" id="btnGuardarPrecio">Guardar Precio</button>
                            </div>
                        </div>
                    </div>
                    </form>
                    <div id="divPreciosTable">
                        <table class="table table-hover table-striped" id="tablePrecios">
                            <thead>
                                <tr>
                                    <th>Valor</th>
                                    <th>Desde</th>
                                    <th>Hasta</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr><td colspan="3"><i class="fa fa-circle-o-notch fa-spin"></i></td></tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--  /MODAL AGREGAR PRECIOS  -->

    <!--  MODAL AGREGAR TIPO  -->
    <div class="modal fade" id="modalAgregarTipo" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content panel-info">
                <div class="modal-header panel-heading">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">Nuevo tipo de producto</h4>
                </div>
                <div class="modal-body">
                    <form id="formTipo">
                        <div class="form-group row">
                            <div class="col-sm-9">
                                <label for="tipoNombre" class="control-label">Tipo</label>
                                <div>
                                    <input type="text" class="form-control" id="tipoNombre" name="tipoNombre">
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <label for="btnGuardarTipo" class="control-label">&nbsp;</label>
                                <div>
                                    <button class="btn btn-primary" type="button" id="btnGuardarTipo">Guardar Tipo</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!--  /MODAL AGREGAR TIPO  -->

    <!--  MODAL AGREGAR MARCA  -->
    <div class="modal fade" id="modalAgregarMarca" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content panel-info">
                <div class="modal-header panel-heading" role="alert">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">Nueva marca de producto</h4>
                </div>
                <div class="modal-body">
                    <form id="formMarca">
                        <div class="form-group row">
                            <div class="col-sm-9">
                                <label for="marcaNombre" class="control-label">Marca</label>
                                <div>
                                    <input type="text" class="form-control" id="marcaNombre" name="marcaNombre">
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <label for="btnGuardarMarca" class="control-label">&nbsp;</label>
                                <div>
                                    <button class="btn btn-primary" type="button" id="btnGuardarMarca">Guardar Marca</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!--  /MODAL AGREGAR MARCA  -->

<?php echo $view->render('FiestissimaCRM:Default:footer.html.php'); ?>